﻿/* ==============================================================================
 * 功能描述：BattlePanelMonsterInfo  
 * 
 * 创 建 者：郑镇泉
 * 
 * 创建日期：2016/4/26 21:06:27
 * ==============================================================================*/
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using ZZQFrameWork;

public class BattlePanelMonsterInfo : MonoBehaviour
{
    private Text nameText;
    private Slider hpSlider;
    private Text hpText;
    private Text infoText;

    private MonsterVO data;

    public MonsterVO Data
    {
        get { return data; }
        set
        {
            data = value;
            UpdateShow();
        }
    }

    void Awake()
    {
        nameText = transform.GetComponentByPath<Text>("Name");
        hpSlider = transform.GetComponentByPath<Slider>("HpSlider");
        hpText = transform.GetComponentByPath<Text>("HpSlider/Value");
        infoText = transform.GetComponentByPath<Text>("Info");
    }

    private void UpdateShow()
    {
        if (Data == null)return;
        nameText.text = Data.name;
        hpText.text = Data.hp + "/" + Data.maxHp;
        hpSlider.value = (float)Data.hp/Data.maxHp;
        infoText.text = Data.des;
    }

    public void UpdateHp(int hp, int maxHp)
    {
        hpText.text = hp + "/" + maxHp;
        hpSlider.value = (float) hp/maxHp;
    }
}